<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of mydbActiveRecord
 *
 * @author I062261
 */
class BWActiveRecord extends CActiveRecord {

    private static $connectionList = array();
    protected $_errors = array();

    //put your code here
    public function getDbConnection() {

        //if (!$app instanceof BApp)
        $app = Blyn::app()->getActiveApp();
        $appClass = get_class($app);

        if (isset(self::$connectionList[$appClass])) {
            $conn = self::$connectionList[$appClass];
            if ($conn instanceof CDbConnection)
                return $conn;
        }

        $conn = $app->getDbAdapter()->getDbConnection();
        if ($conn instanceof CDbConnection) {
            self::$connectionList[$appClass] = $conn;
            return $conn;
        }

        //default connection
        $conn = self::$connectionList[$appClass] = parent::getDbConnection(); //yii::app()->mydb2;
        return $conn;
    }

}

?>
